package com.hangwei.paperless.adapter.sub;

import android.os.Build;
import android.support.annotation.Nullable;
import android.text.Html;
import android.text.Spanned;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseViewHolder;
import com.hangwei.paperless.R;
import com.hangwei.paperless.model.bean.SubProcessListAll;
import com.hangwei.paperless.view.SealHelper;
import com.twelve.all.adapter.MyAdapter;
import com.twelve.all.utils.Tools;

import java.util.List;

/**
 * Created by 张龙臣 on 2020/12/8.
 */

public abstract class SubProcessListStepAdapter extends MyAdapter<SubProcessListAll.StepListBean, BaseViewHolder> {

    public SubProcessListStepAdapter( @Nullable List<SubProcessListAll.StepListBean> data) {
        super(R.layout.item_sub_prosess_setp, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final SubProcessListAll.StepListBean item) {
        String source = Tools.checkedString(item.description);
        String all = source.replaceAll("<p>", "<p  style=\"display:block;margin:0 0;\">");
        Spanned html;
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N)
            html = Html.fromHtml(all, Html.FROM_HTML_MODE_COMPACT);
        else html = Html.fromHtml(all);
        helper.setText(R.id.tvSeq, Tools.checkedString(item.seq))
                .setText(R.id.tvDes,html);
        RelativeLayout flUserSeal = helper.getView(R.id.flUserSeal);
        SealHelper sealHelper = new SealHelper(mContext) {
            @Override
            protected void onSeal() {
                seal(item.id);
            }
        };
        sealHelper.bindData(new SealHelper.SealBean(true,item.technicianStampId,item.technicianId,item.technicianStampTypeCode,item.technicianStampCode,item.technicianDate,item.technician,item.canSeal));
        flUserSeal.removeAllViews();
        flUserSeal.addView(sealHelper.getItemView());
    }

    protected abstract void seal(String id);
}
